/*
 *  Utils.c
 *
 *
 *  Created by Akito van Troyer on 12/1/10.
 *  Copyright 2010 Akito van Troyer. All rights reserved.
 *
 */

#include "Utils.h"

uint8_t get_random8(uint8_t seed)
{
	static uint8_t z=1,w=1;
    z = 269 * (seed & 255) + (seed >> 6);
    w = 180 * (w & 255) + (w >> 6);
    return (z << 8) + w;  /* 8-bit result */
}

uint16_t get_random16(uint16_t seed)
{
	static uint16_t z=1,w=1;
    z = 269 * (seed & 65536) + (seed >> 6);
    w = 2560 * (w & 65536) + (w >> 6);
    return (z << 8) + w;  /* 16-bit result */
}


uint16_t scale(uint16_t num, uint16_t minNum,uint16_t maxNum,uint16_t scaleMin,uint16_t scaleMax){
	if((maxNum == minNum) || (scaleMax == scaleMin)){
		return num;
	}
	else {
		return (((num-minNum)/(maxNum-minNum))*(scaleMax-scaleMin))+scaleMin;
	}
}
